package com.gene.controller.contentCategory;


import com.gene.pojo.TbContentCategory;
import com.gene.service.ITbContentCategoryService;
import com.gene.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内容分类
 */
@Controller
@RequestMapping("/gene-safe/category")
public class TbContentCategoryController {
    @Autowired
    private ITbContentCategoryService iTbContentCategoryService;
    /**
     * 查询所有分类,类目ID=0时，代表的是一级的类目
     * @return
     */
    @RequestMapping(value = "/query")
    @ResponseBody
    public ResultData query(@RequestParam(defaultValue = "0")Integer parentId){
        ResultData result=new ResultData();
        List<TbContentCategory> list=iTbContentCategoryService.query(parentId);
        if(list.size()>0){
            result.setData(list);
            result.setStatus("1");
            result.setMsg("查询成功！");
        }else{
            result.setStatus("0");
            result.setMsg("没有数据！");
        }
        return  result;
    }
    /**
     * 根据分类ID修改
     * @param tbContentCategory
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public ResultData update(TbContentCategory tbContentCategory){
        ResultData result=new ResultData();
        boolean bool=iTbContentCategoryService.update(tbContentCategory);
        if (bool){
            result.setStatus("1");
            result.setMsg("修改成功...");
        }else{
            result.setStatus("0");
            result.setMsg("修改失败！");
        }
        return result;
    }
    /**
     * 添加分类
     * @param tbContentCategory
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public ResultData save(TbContentCategory tbContentCategory){
        ResultData result=new ResultData();
        boolean bool=iTbContentCategoryService.save(tbContentCategory);
        if (bool){
            result.setStatus("1");
            result.setMsg("新增成功...");
        }else{
            result.setStatus("0");
            result.setMsg("新增失败！");
        }
        return result;

    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ResponseBody
    public ResultData del(@RequestParam("id") Integer id,@RequestParam("status") Integer status){
        ResultData result=new ResultData();
        boolean bool=iTbContentCategoryService.del(id,status);
        if (bool){
            result.setStatus("1");
            result.setMsg("删除成功...");
        }else{
            result.setStatus("0");
            result.setMsg("删除失败！");
        }
        return result;
    }
}
